/*************************************************************************************/
/*  HTML5-Canvas-Presentation & Editor (create presentations with a clear structure) */
/*  Copyright (C) 2012  Michael Fürst                                                */
/*                                                                                   */
/*  This program is free software; you can redistribute it and/or modify it          */
/*  under the terms of the GNU General Public License as published by the            */
/*  Free Software Foundation; either version 3 of the License, or (at your           */
/*  option) any later version.                                                       */
/*                                                                                   */
/*  This program is distributed in the hope that it will be useful, but              */
/*  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY       */
/*  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License          */
/*  for more details.                                                                */
/*                                                                                   */
/*  You should have received a copy of the GNU General Public License along          */
/*  with this program; if not, see <http:/* www.gnu.org/licenses/>.                  */
/*************************************************************************************/

var data_width = 1024;
var data_height = 768;

var texts = [];
var boxes = [];
var circles = [];
var lines =  [];
var imgs =  [];
var vids =  [];
var audios =  [];

var path = [];

var gui = false;
var presentation_keylistener = null;
var render = "";
var background = "";
var enableGUI_parser = true;
var menue = false;
var cur_step = 0;
var pos = {x: 0, y:0, angle:0, scalar:0};

var theme_default = {red:255, green:255, blue:255, alpha:1, background:""};
var theme_clean = {red:255, green:255, blue:255, alpha:1, background:""};
var theme_technical = {red:255, green:255, blue:255, alpha:1, background:""};
var theme_fresh = {red:255, green:255, blue:255, alpha:1, background:""};

function mouseClickHandler (x, y, angle, scalar, partial, presstime) {
	if (presstime >= 2000) {
		/* mobiles have no F2 so use extremly long click like F2 */
		toggle_fullscreen();
	} else  if (presstime > 1000) {
		if (gui == true) {
			/* Menue */
			menue = true;
			menuepos = 0;
			pos.x = x;
			pos.y = y;
			pos.angle = -angle;
			pos.scalar = scalar;
		}
	} else if (menue == true) {
		/* menue actions */
		menue_click(x,y,angle,scalar);
	}
}

function keyListener (e) {
	if (e.keyCode == KEY_F2) {
		toggle_fullscreen();
		confirmReaction();
	} else if (e.keyCode == KEY_F4) {
		confirmReaction();
	}
}
function keyListener2 (key, angle, scalar, partial) {
	if (key == KEY_F2) {
		toggle_fullscreen();
		confirmReaction();
	} 
}

function toggle_fullscreen() {
	gui = !gui;
	Presentation.setBottompane(gui);
	Presentation.setKeyboardInputState(gui);
	Presentation.setScreenmode(gui);
	if (gui == true) {
		window.onkeydown = presentation_keylistener;
	} else {
		window.onkeydown = keyListener;
	}
}

function data_background(step, percent) {
	JSLinker.background_func(step, percent);
	cur_step = step;
}

function data_init() {
	presentation_keylistener = window.onkeydown;
	window.onkeydown = keyListener;
	Presentation.setKeyhandler(keyListener2);
	Presentation.debug(true);
	Presentation.setBottompane(false);
	Presentation.setKeyboardInputState(false);
	JSLinker.toFile();
	Presentation.setMousehandler(mouseClickHandler);
	Presentation.clearPath();
	confirmReaction();
	init_menue();
}

function data_render() {
	if (gui == false) {
		menue = false;
	}
	/* draw from data objects */
	JSLinker.render_func();
	Presentation.colorRGB(255,255,255);
	if (menue == true) {
		render_menue();
	}
}
